<?php
	
	class focusAction extends userAction{
		protected  function _initialize(){ //初始化action,用于判断用户登录与否？
			parent::_initialize();
		}
		public function index(){
			//我的好友
			isset($_GET["u"]) ? $u = safeRequest($_GET["u"]) : $u = "all";
			if("all" == $u){
				$friendIds = getFriendList($this->userInfo['id']);
				//最新60条feed
				$feedList = D("feed")->findAll("userid in ($friendIds)","*","regtime desc","60");
				//好友申请
				$friendRequest = D("friends_requests")->count("userid=".$this->userInfo['id'],"id");
				//圈人请求
				$qrequest = D("albums_photos_tags_request")->count("userid=".$this->userInfo['id'],"id");
				//群组邀请
				$groupInvite = D("groups_invites")->count("userid=".$this->userInfo['id'],"id"); 
				//群组申请
				$groupRequest = D("groups_requests")->count("managerid=".$this->userInfo['id'],"id");
				//通知
				$notify = D("notify")->count("userid=".$this->userInfo['id']." and isread=0","id");
				//招呼
				$hello = D("hello")->findAll("userid=".$this->userInfo['id']);


				//guangla新人
				$newUser = D("user")->findAll("","id,username,network_city,faceimg","regtime desc","8");
				
				$this->assign("feedList",$feedList);
				$this->assign("friendRequest",$friendRequest);
				$this->assign("groupInvite",$groupInvite);
				$this->assign("groupRequest",$groupRequest);
				$this->assign("qrequest",$qrequest);
				$this->assign("notify",$notify);
				$this->assign("newuser",$newUser);
				
				$this->assign("hello",$hello);
				$this->display();
			}else{
				$this->rank = getRank($this->userInfo['id'],$u,"feed");
				if(!$this->rank){
					redirect(__APP__."/rank/norank/u/".$u);
					return false;
				}
				isset($_GET["g"]) ? $g = safeRequest($_GET["g"],1) : $g = "all";
				$where  = "userid=".$u." and ";
				"all" == $g ? $where.="1=1" : $where.= "module='".$g."'";
				$feedList = D("feed")->findAll($where,"","regtime desc",60);
				$this->assign("feedList",$feedList);
				if($u != $this->userInfo['id']){
					$userInfo = D("user")->find("id=".$u,"id,username");
					$this->assign("userInfo",$userInfo);
				}
				$this->assign("myid",$this->userInfo['id']);
				$this->display("my");
			}
		}
		
		/**
		 * 随便看看
		 *
		 */
		public function see(){
			$feedList = D("feed")->findAll("","*","regtime desc","60");
			$newUser = D("user")->findAll("","id,username,network_city","regtime desc","8");
			$this->assign("feedList",$feedList);
			$this->assign("newuser",$newUser);
			$this->display();
		}
		
		/**
		 * 群组邀请
		 *
		 */
		public function groupinvite(){
			$groupInvite = D("groups_invites")->findAll("userid=".$this->userInfo['id']);
			$this->assign("list",$groupInvite);
			$this->display(); 
		}
		
		/**
		 * 好友请求
		 *
		 */
		public function friendrequest(){
			$list = D("friends_requests")->findAll("userid=".$this->userInfo['id']);
			$this->assign("list",$list);
			$this->display(); 
		}

		/**
		 * 圈人请求
		 *
		 */
		public function qrequest(){
			$list = D("albums_photos_tags_request")->findAll("userid=".$this->userInfo['id']);
			$this->assign("list",$list);
			$this->display(); 
		}
		
		/**
		 * 群组加入请求
		 *
		 */
		public function getgrouprequest(){
			$list = D("groups_requests")->findAll("managerid=".$this->userInfo['id']);
			$this->assign("list",$list);
			$this->display(); 
		}
		
		/**
		 * 删除动态
		 *
		 */
		public function delfeed(){
			$id = safeRequest($_GET["id"]);
			if(D("feed")->delete("id=".$id." and userid=".$this->userInfo['id'])){
				isset($_GET["ajax"]) ? print "success" : $this->success(L("delete_success"));
			}else{
				isset($_GET["ajax"]) ? print "error" : $this->error(L("delete_error"));
			}
		}		
	}
?>